/* @ author Anastasia Afonina
 */
// On pressing button 'New Contact' clear fields
// TODO: On pressing 'Save' button - send server via AJAX contact data
function createNewContact() {
	document.getElementById('Contact_id').textContent = 'New Contact';
	document.getElementById('Profile_Name').value = "";
	document.getElementById('Profile_Surname').value = "";
	document.getElementById('Profile_Date').value = "";
	document.getElementById('Profile_MP').value = "";
	document.getElementById('Profile_HP').value = "";
	document.getElementById('Profile_WP').value = "";
	document.getElementById('Profile_Country').value = "";
}

// Function switches contact with it's data in right span
function switchContact() {
	contactName = $(this).find(':selected').text();
	contactSurname = document.getElementById('Profile_Surname').value;
	contactBirthDate = document.getElementById('Profile_Date').value;
	contactMobilePhone = document.getElementById('Profile_MP').value;
	contactHomePhone = document.getElementById('Profile_HP').value;
	contactWorkPhone = document.getElementById('Profile_WP').value;
	contactCountry = document.getElementById('Profile_Country').value;
	document.getElementById('Profile_Name').value = contactName;
	document.getElementById('Profile_Surname').value = contactSurname;
	document.getElementById('Profile_Date').value = contactBirthDate;
	document.getElementById('Profile_MP').value = contactMobilePhone;
	document.getElementById('Profile_HP').value = contactHomePhone;
	document.getElementById('Profile_WP').value = contactWorkPhone;
	document.getElementById('Profile_Country').value = contactCountry;
	$('legend#Contact_id').text(contactName + " " + contactSurname + " Profile");
};

// Assign <legend> of form when switching contacts from the list using
// switchContact function
// TODO NOT WORKING IN CHROME!
$(document).ready(function() {
	$("#contacts_list").change(switchContact);
});

// Show fields for additional Home number after selecting check-box
function addHomeNumber() {
	if (document.getElementById('Profile_inlineCheckbox1').checked == true) {
		$("#Profile_HPtext, #Profile_HP").show();
	} else {
		$("#Profile_HPtext, #Profile_HP").hide();
	}
};

// Show fields for additional Work number after selecting check-box
function addWorkNumber() {
	if (document.getElementById('Profile_inlineCheckbox2').checked == true) {
		$("#Profile_WPtext, #Profile_WP").show();
	} else {
		$("#Profile_WPtext, #Profile_WP").hide();
	}
};

